package com.test.rabbitmq.nack;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Consumer {


    public static void main(String[] args)throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setVirtualHost("testhost");
        factory.setPort(Config.MQ_PORT);
        factory.setHost(Config.MQ_IP);
        factory.setUsername(Config.USER_NAME);
        factory.setPassword(Config.USER_PWD);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(Config.EXCHANGE_NAME, Config.EXCHANGE_TYPE, true, false, null);
        channel.queueDeclare(Config.QUEUE_NAME, true, false, false, null);
        channel.queueBind(Config.QUEUE_NAME, Config.EXCHANGE_NAME, Config.ROUTE_KEY);
        // 由于消费段的ack是手工签收，所以 autoAck = false
        channel.basicConsume(Config.QUEUE_NAME, false, new MyConsumer(channel));
    }
}
